import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
import TableControls from '#cpt/temp/TableControls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))
const ControlModal 			= $Lazy.state(()=>import('./cpt/control-modal'))
const $time 				= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '科室',		name: 'project_parent_id',				type: 'select', loading:true, idStr:'uuid',nameStr:'name' },
			{ label: '岗位',		name: 'project_id',						type: 'select', loading:true },
			{ label: '检测项目',		name: 'kind_id', 						type: 'select', loading:true },
			// { label: '账单状态',		name: 'bill_status',					type: 'select', loading:true },
			{ label: '接收时间',		names: ['start_at','end_at'], 			type:'date-range', name:'jz-time' },
			// { label: '账单时间',		names: ['bill_start_at','bill_end_at'], type:'date-range', name:'jz-time1' },
		],
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		$time.then(f=>{
			const arr = f.duration['2-9-9']()
			this.resetModel = { start_at: arr[0], end_at: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			if(window.isInit){
				this.fetch()
			}
		})
	}
	//获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 账单状态
			// $fn.setRow( forms, 'bill_status', await f.getDisCache({ code: 45300 }) )
			// 科室
			$fn.setRow( forms, 'project_parent_id', await f.getCache({ api:'ke_shi' } ) )
			// 岗位
			$fn.setRow( forms, 'project_id', await f.getCache({ api:'gang_wei' } ) )
			// 检测项目
			$fn.setRow( forms, 'kind_id', await f.getCache({ api:'project_name' } ) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'statistics/labSingleTestResultCount', {
		callback: result => this.setState({ result })
	})
	
	// 表单
	cols = [
		{ title: '科室', 			dataIndex: 'project_parent_name', 		width:150 },
		{ title: '岗位', 			dataIndex: 'project_name', 				width:150 },
		{ title: '自然项目', 		dataIndex: 'parent_kind_name', 			width:200 },
		{ title: '检测项目名称', 	dataIndex: 'single_kind_name', 			width:200 },
		{ title: '检测数量', 		dataIndex: 'count_total', 				...$fn.table.num },
		// { title: '收费标准', 		dataIndex: 'sprice_total', 				...$fn.table.num },
		// { title: '实际收费', 		dataIndex: 'price_total', 				...$fn.table.num },
		TableControls.controls.call(this)
	]
	
	// 表格操作按钮
	table_controls = (text, rows) => {
		const { start_at, end_at, bill_start_at, bill_end_at } = this.model
		return [
			TableControls.click.call(this, '项目明细', ()=> this.modal.open({...rows, start_at, end_at, bill_start_at, bill_end_at}) )
		]
	}
	
	// 操作按钮
	controls = () => {
		return [
			Controls.exports.call(this, 'statistics/labSingleTestResultCount'),			// 导出
		]
	}
	
	render(){
		const { result } = this.state
		return (
			<>
				<Page title='测试数统计' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this, {timeStr:'2-9-9'}) }
					{/* 表格 */}
					{ 
						Table.call(this,
						{ isInit:window.isInit,
							suffix: (
								<>
									<div className='ml10 g9'>当前页总检测数量 <b className='f14 c0'>{result?.current_page_total}</b></div>
									{/*<div className='ml10 g9'>当前页总收费标准 <b className='f14 c0'>{result?.current_page_price_total}</b></div>
									<div className='ml10 g9'>当前页总实际收费 <b className='f14 c0'>{result?.current_page_sprice_total}</b></div>*/}
								</>
							),
							isIndex: 1
						})
					}
				</Page>
				{/* 项目明细弹窗 */}
				<ControlModal onRef={ref=>this.modal=ref} />
			</>
		)
	}
}

export default Index